package com.bignerdranch.android.myapplication;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.bignerdranch.android.myapplication.WAPfunctions.PlanActivity;
import com.bignerdranch.android.myapplication.WAPfunctions.WeatherActivity;

/**
 * Created by T540p on 2017/7/11.
 */

public class FuncFragment extends Fragment {
    private Button mLearning,mPlan,mWeather;
    @Override
    public void onCreate(Bundle saveInstanceState){
        super.onCreate(saveInstanceState);


    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View v=inflater.inflate(R.layout.func_interface,container,false);

        mLearning=(Button)v.findViewById(R.id.learning_button);
        mPlan=(Button)v.findViewById(R.id.plan_button_func);
        mWeather=(Button)v.findViewById(R.id.whether_button_func);

        mLearning.setOnClickListener(new View.OnClickListener() {
                                         @Override
                                         public void onClick(View v) {
                                             Intent intent=new Intent(getActivity(),CourseActivity.class);
                                             getActivity().startActivityForResult(intent,7);
                                         }
                                     });

        mPlan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String planType = "日计划";
                Intent intent = new Intent(getActivity(), PlanActivity.class);
                intent.putExtra("planType",planType);
                getActivity().startActivityForResult(intent,7);
            }
        });

        mWeather.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String weatherId = "CN101270106";
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
                Intent intent = new Intent(getActivity(), WeatherActivity.class);
                if (prefs.getString("weather", null) == null) {
                    intent.putExtra("weather_id",weatherId);
                }
                getActivity().startActivityForResult(intent,7);
            }
        });
        return v;
    }


}
